package com.qfedu.mesadmin.dev.type.service.Impl;

import com.qfedu.mes.entity.dev.DeviceType;
import com.qfedu.mes.exception.CommonException;
import com.qfedu.mesadmin.dev.type.dao.DeviceTypeDAO;
import com.qfedu.mesadmin.dev.type.params.AddTypeParam;
import com.qfedu.mesadmin.dev.type.params.SearchParam;
import com.qfedu.mesadmin.dev.type.service.DeviceService;
import com.qfedu.mesadmin.dev.type.vo.DeviceTypeVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DeviceServiceImpl implements DeviceService {
    @Resource
    private DeviceTypeDAO deviceTypeDAO;
    @Override
    public void addDevice(AddTypeParam param) {
        DeviceType deviceType=new DeviceType();
        BeanUtils.copyProperties(param,deviceType);
        DeviceType deviceType1 = deviceTypeDAO.selectById(deviceType.getId());
        if (deviceType1!=null){
            throw new CommonException("该设备已经存在");
        }
        deviceTypeDAO.insert(deviceType);
    }

    @Override
    public List<DeviceTypeVO> selectDevTypeTree() {
        List<DeviceTypeVO> deviceTypeVOS = deviceTypeDAO.selectDevTypeTree();
        return deviceTypeVOS;
    }

    @Override
    public List<DeviceType> selectLike(SearchParam param) {
        List<DeviceType> deviceTypes = deviceTypeDAO.selectLike(param);
        return deviceTypes;
    }

    @Override
    public void updateDev(DeviceType deviceType) {
        deviceTypeDAO.update(deviceType);
    }

    @Override
    public DeviceType devInfo(Integer id) {
        DeviceType deviceType = deviceTypeDAO.selectById(id);
        return deviceType;
    }
}
